package com.gmstu.springframework.aop.aspect;

import com.gmstu.springframework.aop.intercept.GpMethodInterceptor;
import com.gmstu.springframework.aop.intercept.GpMethodInvocation;

import java.lang.reflect.Method;

/**
 * @author John.zhang
 * @version Id: GpMethodBeforeAdviceInterceptor, v 1.0 2020/8/26 17:28 ZhiYong Exp $
 */
public class GpMethodBeforeAdviceInterceptor extends GpAbstractAspectAdvice implements GpMethodInterceptor {

    private GpJoinPoint joinPoint;

    public GpMethodBeforeAdviceInterceptor(Method aspectMethod, Object aspectTarget) {
        super(aspectMethod, aspectTarget);
    }

    private void before(Method method, Object[] args, Object object) throws Throwable {
        super.invokeAdviceMethod(joinPoint, null, null);
    }

    @Override
    public Object invoke(GpMethodInvocation invocation) throws Throwable {
        this.joinPoint = invocation;
        before(invocation.getMethod(), invocation.getArguments(), invocation.getThis());
        return invocation.proceed();
    }
}
